package ro.ubbcluj.cs.damate.persistence.entities;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;

import static javax.persistence.CascadeType.*;
import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.*;

/**
 * @author Lóránd Fazakas (lorand)
 *         Date: 4/22/12
 *         Time: 1:12 AM
 */
@Table(name = "event_type", catalog = "damate")
@Entity
public class EventType {

    private Long eventTypeId;

    @Column(name = "eventTypeId", nullable = false, insertable = true, updatable = true, length = 10, precision = 0)
    @Id
    @GeneratedValue(strategy= IDENTITY)
    public Long getEventTypeId() {
        return eventTypeId;
    }

    public void setEventTypeId(Long eventTypeId) {
        this.eventTypeId = eventTypeId;
    }

    private String name;

    @Column(name = "name", nullable = false, insertable = true, updatable = true, length = 45, precision = 0)
    @Basic
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private int code;

    @Column(name = "code", nullable = false, insertable = true, updatable = true, length = 10, precision = 0)
    @Basic
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    private String paramIndex;

    @Column(name = "paramIndex", nullable = true, insertable = true, updatable = true, length = 45, precision = 0)
    @Basic
    public String getParamIndex() {
        return paramIndex;
    }

    public void setParamIndex(String paramIndex) {
        this.paramIndex = paramIndex;
    }

    private List<Event> events;

    @OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "eventType")
    public List<Event> getEvents() {
        return events;
    }

    public void setEvents(List<Event> events) {
        this.events = events;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EventType that = (EventType) o;

        if (code != that.code) return false;
        if (eventTypeId != that.eventTypeId) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        if (paramIndex != null ? !paramIndex.equals(that.paramIndex) : that.paramIndex != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = eventTypeId.intValue();
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + code;
        result = 31 * result + (paramIndex != null ? paramIndex.hashCode() : 0);
        return result;
    }
}
